<template>
	<view class="home">
		<swiper class="swiper" indicator-dots :autoplay="true" :interval="2000" circular>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<view class="nav">
			<view class="item">
				<view class="iconfont icon-ziyuan"></view>
				<text>黑马超市</text>
			</view>
			<view class="item">
				<view class="iconfont icon-tupian"></view>
				<text>社区图片</text>
			</view>
			<view class="item">
				<view class="iconfont icon-guanyuwomen"></view>
				<text>联系我们</text>
			</view>
			<view class="item">
				<view class="iconfont icon-shipin"></view>
				<text>学习视频</text>
			</view>
		</view>
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<!-- 一般用法 -->
			<view class="goods_list">
				<view class="goods_item" v-for="item in goods" :key="item.id">
					<image :src="item.img_url"></image>
					<view class="price">
						<text>{{item.sell_price}}</text>
						<text>{{item.market_price}}</text>
					</view>
					<view class="name">{{item.title}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				swipers: [],
				goods: []
			}
		},
		onLoad() {
			this.getSwipers()
			this.getGoods()
		},
		methods: {
			async getSwipers () {
				const res = await this.$myRequest({
					url: '/api/getlunbo'
				})
				this.swipers = res.data.message
			},
			// 获取推荐商品
			async getGoods () {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=1'
				})
				this.goods = res.data.message
			}
		}
	}
</script>

<style lang="scss">
	.home{
		swiper{
			height: 380rpx;
			image{
				width: 750rpx;
				height: 380rpx;
			}
		}
		.nav{
			display: flex;
			align-items: center;
			.item{
				width: 25%;
				text-align: center;
				view{
					background: $shop-color;
					line-height: 120rpx;
					width: 120rpx;
					height: 120rpx;
					border-radius: 90px;
					margin:10px auto;
				}
				text{
					font-size: 15px;
				}
			}
			.iconfont{
				font-size: 25px;
				color: #fff;
				height: 50px;
			}
			.icon-tupian{
				font-size: 20px;
			}
		}
		.hot_goods {
			background: #eee;
			.tit{
				border-top: 2px solid #eee;
				border-bottom: 2px solid #eee;
				margin-top: 20px;
				margin-bottom: 3px;
				color: $shop-color;
				height: 50px;
				line-height: 50px;
				text-align: center;
				letter-spacing: 20px;
				background: #fff;
			}
		    .goods_list {
				display: flex;
				padding: 0 15rpx;
				justify-content: space-between;
				overflow: hidden;
				flex-wrap: wrap;
				.goods_item {
					width: 355rpx;
					margin-bottom: 15rpx;
					background: #fff;
					padding: 10px;
					box-sizing: border-box;
					image{
						height: 150px;
						width: 150px;
						display: block;
						margin: 10px auto;
					}
					.price{
						font-size: 18px;
						color: red;
						padding: 8px 0;
						text:nth-child(2){
							color: #ccc;
							text-decoration: line-through;
							margin-left: 10px;
							font-size: 13px;
						}
					}
					.name {
						font-size: 14px;
						
					}
				}
			}
		}
	}
</style>
